package com.souku.finance.application.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.souku.finance.application.R;

/**
 * Created by Android on 2017/1/17.
 */

public class SimpleDialog extends Dialog implements View.OnClickListener {
    protected View rootView;
    protected TextView tvTitle;
    protected Button btnCancel;
    protected Button btnOk;
    private OnClick onClick;
    private boolean ischannel;
    private String title;

    public SimpleDialog(Context context, String title, final OnClick onClick, boolean ischannel) {
        super(context, R.style.myDialogFullNo);
        this.onClick=onClick;
        this.title=title;
        this.ischannel=ischannel;
    }

    public SimpleDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected SimpleDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_simple);
        initView();
        if (ischannel) {
            btnCancel.setVisibility(View.VISIBLE);
        } else {
            btnCancel.setVisibility(View.GONE);
        }
        tvTitle.setText(title);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_cancel) {
            onClick.cancel();
        } else if (view.getId() == R.id.btn_ok) {
            onClick.ok();
        }
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        btnCancel = (Button) findViewById(R.id.btn_cancel);
        btnCancel.setOnClickListener(SimpleDialog.this);
        btnOk = (Button) findViewById(R.id.btn_ok);
        btnOk.setOnClickListener(SimpleDialog.this);
    }

    public interface OnClick {
        void ok();
        void cancel();
    }
}
